package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysMenuService;
import com.atguigu.spzx.model.entity.system.SysMenu;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: SysMenuController
 * @Package: com.atguigu.spzx.manager.controller
 * @Description 菜单管理
 * @Author 孤妤
 * @Date: 2023/12/6 9:39
 */
@RestController
@RequestMapping("/admin/system/sysMenu")
@Tag(name = "菜单管理")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;

    @GetMapping("/findAllSysMenu")
    @Operation(summary = "查询菜单列表")
    public Result<List<SysMenu>> findAllSysMenu() {
        List<SysMenu> sysMenuList = sysMenuService.findAllSysMenu();
        return Result.build(sysMenuList, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("/addSysMenu")
    @Operation(summary = "添加主子节点")
    public Result addSysMenu(@RequestBody SysMenu sysMenu) {
        sysMenuService.addSysMenu(sysMenu);
        return Result.build(null, ResultCodeEnum.SUCCESS).setMsg("节点添加成功");
    }

    @GetMapping("/findSysMenuById/{id}")
    @Operation(summary = "根据id查询菜单信息")
    public Result<SysMenu> findSysMenuById(@PathVariable Long id) {
        SysMenu sysMenu = sysMenuService.findSysMenuById(id);
        return Result.build(sysMenu, ResultCodeEnum.SUCCESS);
    }

    @PutMapping("/updateSysMenu")
    @Operation(summary = "修改菜单信息")
    public Result changeSysMenu(@RequestBody SysMenu sysMenu) {
        sysMenuService.changeSysMenu(sysMenu);
        return Result.build(null, ResultCodeEnum.SUCCESS).setMsg("修改成功");
    }

    @DeleteMapping("/deleteSysMenuById/{id}")
    @Operation(summary = "根据id删除菜单")
    public Result removeSysMenuById(@PathVariable Long id) {
        sysMenuService.removeSysMenuById(id);
        return Result.build(null, ResultCodeEnum.SUCCESS).setMsg("删除成功");
    }

    @GetMapping("/findAssign/{id}")
    @Operation(summary = "根据角色id回显菜单")
    public Result<List<Long>> findSysMenuEcho(@PathVariable Long id) {
        List<Long> longList = sysMenuService.findSysMenuEcho(id);
        return Result.build(longList, ResultCodeEnum.SUCCESS);
    }
}

